package com.example.mapp;

import com.example.entity.ApplyRepair;
import com.example.ext.entity.ExtApplyRepair;
import com.example.mapp.buildSql.ApplyRepairMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by douyx on 2018/03/25.
 */
@Mapper
public interface ApplyRepairMapp {

	@Select(" select a.*, b.party_name as maintenancePartyName,d.party_name as usedPartyName, c.elevator_num as elevatorNum from apply_repair a "
			+ " left join party b on a.maintenance_party_id = b.id left join elevator c on a.elevator_id=c.id "
			+ " left join party d on a.used_party_id = d.id" + " where a.id=#{id}")
	ExtApplyRepair queryById(String id) throws Exception;

	@SelectProvider(type = ApplyRepairMappSql.class, method = "queryList")
	List<ExtApplyRepair> queryList(ExtApplyRepair extApplyRepair) throws Exception;

	@Update(" update apply_repair set approve_status=#{approveStatus},refuse_reason=#{refuseReason} , approve_user_id =#{approveUserId}"
			+ ",deal_status=#{dealStatus},maintenance_used_url=#{maintenanceUsedUrl},used_user_url=#{usedUserUrl}"
			+ ",repair_time=#{repairTime},deal_time=#{dealTime} where id=#{id} ")
	public int update(ApplyRepair applyRepair) throws Exception;

	@Insert(" insert into apply_repair (party_name,blocks_num,apply_time,recorder_name,apply_question,deal_way,approve_status,refuse_reason,"
			+ "apply_type,elevator_id,used_party_id,maintenance_party_id, deal_status,maintenance_used_url,used_user_url,repair_time,deal_time,cost,approve_user_id) "
			+ " value "
			+ " (#{partyName},#{blocksNum},#{applyTime},#{recorderName},#{applyQuestion},#{dealWay},#{approveStatus},#{refuseReason},#{applyType},#{elevatorId},"
			+ "#{usedPartyId},#{maintenancePartyId}, #{dealStatus},#{maintenanceUsedUrl},#{usedUserUrl},#{repairTime},#{dealTime},#{cost},#{approveUserId})")
	@SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
	public int add(ApplyRepair applyRepair) throws Exception;
}
